const KoaRouter = require("@koa/router");
const {
  create,
  updateName,
  updateAvatar,
  getUserInfo,
  getUserAttention,
  getUserSave,
  getUserSupport,
  getUserPublish,
  attentionUser,
  recommendUsers,
  cancelAttentionUser,
  isAttentionUser,
  isSaveArticle,
  isSupportArticle,
  getUserRescueHotline,
} = require("../controller/user.controller");
// 验证用户身份、密码加密的中间件
const { verifyUser, handlePassword } = require("../middleware/user.middleware");
const { verifyAuth } = require("../middleware/authority.middleware");

// 1. 创建路由对象
const userRouter = new KoaRouter({ prefix: "/users" });

// 2. 定义路由中的映射
// 路由做的东西很简单，就是路径和某一个函数的映射关系

// 2.1 用户注册接口
userRouter.post("/register", verifyUser, handlePassword, create);
// 更新用户昵称
userRouter.patch("/updateName", verifyAuth, updateName);
// 更新用户头像
userRouter.patch("/updateAvatar", verifyAuth, updateAvatar);
// 获取用户信息
userRouter.get("/getUserInfo", verifyAuth, getUserInfo);
// 获取用户的关注
userRouter.get("/getUserAttention", verifyAuth, getUserAttention);
// 获取用户的收藏
userRouter.get("/getUserSave", verifyAuth, getUserSave);
// 获取用户的点赞
userRouter.get("/getUserSupport", verifyAuth, getUserSupport);
// 获取用户的发布
userRouter.get("/getUserPublish", verifyAuth, getUserPublish);
// 关注用户
userRouter.post("/attentionUser/:attention_uid", verifyAuth, attentionUser);
// 取消关注
userRouter.delete(
  "/cancelAttentionUser/:attention_uid",
  verifyAuth,
  cancelAttentionUser
);
// 获取是否关注用户
userRouter.get("/isAttentionUser/:attention_uid", verifyAuth, isAttentionUser);
// 获取是否收藏文章
userRouter.get("/isSaveArticle/:article_id", verifyAuth, isSaveArticle);
// 获取是否点赞文章
userRouter.get("/isSupportArticle/:article_id", verifyAuth, isSupportArticle);
// 推荐用户
userRouter.get("/recommendUsers", recommendUsers);
// 获取用户救助热线
userRouter.get("/getUserRescueHotline", getUserRescueHotline);

// 3. 导出路由
module.exports = userRouter;
